package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SysUserControllerApi;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @RequestBody: （前端 ajax）解析请求体json，转换为 pojo
 * @ResponseBody:  把pojo转换为 json （前端ajax）
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class SysUserController implements SysUserControllerApi {


    @Autowired
    SysUserService userService;

    @Override
    @PostMapping("/register")
    public Result<Long> register(SysRegisterDTO sysRegisterDTO) {
        Long userId = userService.register(sysRegisterDTO);
        return Result.success(userId);
    }

    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(@RequestParam("username") String username){
        SysUserDTO userDTO = userService.queryUser(username);

        return Result.success(userDTO);
    }


}
